<?php

namespace app\api\model;
use think\Model;

class Configure extends Model {

	public function setCache() {
		$res = $this->find(1);
		S('config', $res);
		return $res;
	}

	public function update() {

		$result = $this->validate([
			'title' => ['.{1,50}', '网站名称不符合规范'],
			'uname' => ['.{1,50}', '网站名称简写不符合规范'],
			'keywords' => ['.{2,120}', '关键字不符合规范'],
			'description' => ['.{2,440}', '描述不符合规范'],
			'copyright' => ['.{0,220}', '底部版权信息最多只能有110个字符'],
			'record' => ['.{0,50}', '备案号最多只能有50个字符'],
		])->create();

		if (!$result) {
			return $this->getError();
		} else {
			$this->setCache();
			return $this->where(['id' => 1])->save(I('post.'));
		}

	}
}
